home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C++ / Applications / HyperCuber 2.0 / source / CHyperCuberPane.cp < prev    next >
Encoding:
Text File  |  1994-05-03  |  8.3 KB  |  139 lines  |  [TEXT/KAHL]

  1. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2. // CHyperCuberPane.c
  3. //
  4. // This file contains the implementation of the pane for the graphic window.
  5. //___________________________________________________________________________
  6.  
  7. #include "CControlsDirector.h"
  8. #include "CGraphic.h"
  9. #include "CHyperCuberApp.h"
  10. #include "CHyperCuberDoc.h"
  11. #include "CHyperCuberPane.h"
  12. #include "CHyperCuberPrefs.h"
  13. #include "CHyperScrollBar.h"
  14. #include "CRotateMouseTask.h"
  15. #include "HyperCuber Commanths(&width, &height);                //  Find the new size of the pane
  16.     
  17.     Rect change_rect = {0, 0, 0, 0};            //  Make pane fit the aspect ratio
  18.     short size;
  19.     if (width > aspect_ratio * height)
  20.         {
  21.         size = aspect_ratio * height;
  22.         change_rect.right = size - width;
  23.         }
  24.     else
  25.         {
  26.         size = width;
  27.         change_rect.bottom = size / aspect_ratio - height;
  28.         }
  29.         
  30.     ChangeSize(&change_rect, FALSE);
  31.     CenterWithinEnclosure(TRUE, TRUE);    
  32.  
  33.     Rect bounds;
  34.     LongToQDRect(&frame, &bounds);                //  Find size of pane
  35.     
  36.     adjust_offscreen_pixmap(&OffscreenPort,        //  Make offscreen bitmap large enough
  37.                                 &bounds);
  38.     graphic->FitToPane();                            //  Remap the graphic to the new pane size
  39.  
  40. }    //==== CHyperCuberPane::AdjustToEnclosure() ====\\
  41.  
  42.  
  43.  
  44. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  45. // Procedure CHyperCuberPane::UpdateGraphicsPanes
  46. //
  47. // Purpose: Recompute and redraw the graphics pane
  48. //
  49. // Parameters: main_pane: the main pane
  50. //_________________________________________________________
  51.  
  52. void CHyperCuberPane::UpdateGraphicsPanes(void)
  53. {
  54.  
  55.     LongRect graphics_rect;
  56.     Prepare();                                //  Erase the pane
  57.     GetFrame(&graphics_rect);
  58.     LEraseRect(&graphics_rect);                    
  59.  
  60.     Rect no_movement = {0, 0, 0, 0};
  61.     AdjustToEnclosure(&no_movement);        //  Recalc positions of graphics panes
  62.  
  63.     Refresh();                                //  Redraw the object
  64.  
  65. }    //==== CHyperCuberPane::UpdateGraphicsPanes() ====\\
  66.  
  67.  
  68. //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  69. //| CHyperCuberPane::DoClick
  70. //|
  71. //| Purpose: This is called when the user clicks in the pane
  72. //|
  73. //| Parameters: hit_point: the point where the click occurred
  74. //|             modifiers: modifiers from mouseDown event
  75. //|             when:      when the click occurred
  76. //|______________________________________________________________
  77.  
  78. void CHyperCuberPane::DoClick(Point hit_point, short modifiers, long when)
  79. {
  80.  
  81.     Point global_point = hit_point;
  82.     LocalToGlobal(&global_point);                        //  Find click's global coordinates
  83.     if (global_point.v < menubar_height)
  84.         {
  85.         DoCommand(cmdToggleMenuBar);                    //  If the click was in the (hidden) menubar,
  86.         return;                                            //    show the menubar.
  87.         }
  88.  
  89.     mouse_task_struct    h_mouse_tasks[MAX_MOUSE_CONTROLS];
  90.     mouse_task_struct    v_mouse_tasks[MAX_MOUSE_CONTROLS];
  91.     short num_h_tasks = 0;
  92.     short num_v_tasks = 0;
  93.  
  94.     CHyperCuberDoc *doc = (CHyperCuberDoc *) itsSupervisor;    //  Get the document
  95.  
  96.     long graphic_dimension = doc->graphic->dimension;        //  Find dimension of graphic
  97.  
  98.     long i;
  99.     for (i = 0; i < gPrefs->prefs.num_mouse_controls; i++)    //  Loop through all mouse controls
  100.         {
  101.         mouse_control_struct mouse_control =
  102.                     gPrefs->prefs.mouse_controls[i];        //  Get point to mouse controls
  103.         if ((mouse_control.modifiers == modifiers) &&
  104.             (mouse_control.dimension <= graphic_dimension))    //  Use this task if the modifier keys
  105.                                                             //   are right and the dimension is
  106.                                                             //   no more than the graphic dimension
  107.             {
  108.             
  109.             mouse_task_struct mouse_task;
  110.             
  111.             mouse_task.controls_director =
  112.                 (CControlsDirector *)
  113.                     doc->controls_directors->
  114.                         NthItem(mouse_control.dimension);    //  Find controls for this dimension
  115.             
  116.             mouse_task.angle = mouse_control.angle;            //  Get angle to change
  117.             mouse_task.multiplier =
  118.                                 mouse_control.multiplier;    //  Get multiplier
  119.             
  120.             if (mouse_control.horiz)                        
  121.                 h_mouse_tasks[num_h_tasks++] = mouse_task;    //  Add task to horizontal tasks array
  122.             
  123.             else
  124.                 v_mouse_tasks[num_v_tasks++] = mouse_task;    //  Add task to vertical tasks array
  125.             }
  126.         }
  127.  
  128.     CRotateMouseTask *mouse_task = new (CRotateMouseTask);
  129.     mouse_task->IRotateMouseTask(this, h_mouse_tasks,
  130.                 v_mouse_tasks, num_h_tasks, num_v_tasks);    //  Initialize mouse task
  131.  
  132.     LongRect pin_rect = {-10000, -10000, 10000, 10000};
  133.     LongPt long_hit_point;
  134.     QDToLongPt(hit_point, &long_hit_point);    
  135.     TrackMouse(mouse_task, &long_hit_point, &pin_rect);
  136.  
  137. }    //==== CHyperCuberPane::DoClick() ====\\
  138.  
  139.